package io.gitee.yth.design.pattern.test.core.pattern.behavioral.visitor.visitor;

import io.gitee.yth.design.pattern.test.core.pattern.behavioral.visitor.element.BooleanElement;
import io.gitee.yth.design.pattern.test.core.pattern.behavioral.visitor.element.CollectionElement;
import io.gitee.yth.design.pattern.test.core.pattern.behavioral.visitor.element.IntegerElement;
import io.gitee.yth.design.pattern.test.core.pattern.behavioral.visitor.element.StringElement;
import io.gitee.yth.design.pattern.test.core.pattern.behavioral.visitor.element.Visitable;

/**
 * 针对每个Element的具体实现子类，声明一个访问接口
 *
 * @author yth
 * @since 2023-04-29-16:29
 */
public interface Visitor {

    void visitInteger(IntegerElement e);

    void visitBoolean(BooleanElement e);

    void visitString(StringElement e);

    /**
     * 默认实现： 遍历对象结构每个元素
     * 子类可以重写，对遍历方式进行定制
     */
    default void visitCollection(CollectionElement e) {
        for (Visitable v : e.getCollection()) {
            v.accept(this);
        }
    }

}
